<template>
  <div>
  <el-container class="home-container">
    <!-- //头 -->
    <el-header>
      <div>
        <img src="../../assets/logo.png">
        <span>电商后台管理系统</span>
      </div>
    <el-button type="info">退出</el-button>
    </el-header>

    <el-container>
    <!-- //左侧 -->
    <el-aside :width="isCollapse?'64px':'200px'">
      <div class="toggel-button" @click="toggleClient">|||</div>
      <el-menu
      :default-active="activePath"
      router
      :collapse-transition="false"
      :collapse="isCollapse"
      :unique-opened="true"
      background-color="#333333"
      text-color="#fff"
      active-text-color="#33cccc">
      <!-- 一级菜单 -->
      <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
        <!-- 模板 -->
        <template slot="title">
          <!-- 图标 -->
          <i :class="item.icon" class="firsticonfond"></i>
          <!-- 文本 -->
          <span>{{ item.name }}</span>
        </template>

        <!-- 二级菜单 -->
        <el-menu-item
        @click="savedefaultactive(subItem.path)"
        :index="subItem.path"
        v-for="subItem in item.children"
        :key="subItem.id">
          <!-- 模板 -->
          <template slot="title">
          <!-- 图标 -->
            <i :class="subItem.icon" class="secondiconfond"></i>
          <!-- 文本 -->
            <span>{{ subItem.name }}</span>
          </template>
        </el-menu-item>

      </el-submenu>

    </el-menu>
    </el-aside>
    <!-- //中心 -->
    <el-main>
      <router-view></router-view>
    </el-main>
  </el-container>

</el-container>
  </div>
</template>

<script>
import { getMenu } from '@/api/home'
export default {
  name: 'HomeGlpt',
  data () {
    return {
      menulist: [],
      isCollapse: false,
      activePath: ''
    }
  },
  created () {
    this.getList()
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    async getList () {
      const res = await getMenu()
      // console.log(res)
      this.menulist = res.data
    },
    // 折叠展开
    toggleClient () {
      this.isCollapse = !this.isCollapse
    },
    savedefaultactive (value) {
      window.sessionStorage.setItem('activePath', value)
      this.activePath = value
    }
  }
}
</script>

<style scoped lang="less">
.home-container{
  height: 100vh;
}
.el-header{
  background-color: #333333;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: white;
  font-size: 20px;
  >div{
    display: flex;
    align-items: center;
    span{
      margin-left: 20px;
    }
    img{
      width: 80px;
      height: 80px;
    }
  }
}
.el-aside{
  background-color: #333333;
  .el-menu{
    border-right: 0px;
  }
}
.el-main{
  background-color: #dfebeb;
}
.firsticonfond{
  margin-right: 20px;
}
.secondiconfond{
  margin-right: 10px;
}
.toggel-button{
  background-color: #424242;
  font-size: 10px;
  line-height: 24px;
  color: #FFFFE0;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
